package com.nn.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nn.mapper.AroundTravelMapper;
import com.nn.pojo.AroundTravel;
import com.nn.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class AroundTravelImpl implements AroundTravelService {
    @Autowired
    private AroundTravelMapper aroundTravelMapper;

    @Override
    public PageResult getaroundTravelList(PageResult pageResult) {
        IPage page = new Page(pageResult.getPageNum(), pageResult.getPageSize());
        QueryWrapper queryWrapper = new QueryWrapper();
        boolean flag = StringUtils.hasLength(pageResult.getQuery());
        queryWrapper.like(flag, "title", pageResult.getQuery());
        //执行分页查询,返回值依然是分页对象信息
        page = aroundTravelMapper.selectPage(page, queryWrapper);
        //回传5个参数 total/分页后的数据
        long total = page.getTotal();
        List<AroundTravel> rows = page.getRecords();
        return pageResult.setTotal(total).setRows(rows);
    }

    /*修改状态*/
    @Override
    public void updateStatus(AroundTravel aroundTravel) {
        aroundTravelMapper.updateById(aroundTravel);
    }

    /*查询信息*/
    @Override
    public AroundTravel getaroundTravelId(Integer id) {
        return aroundTravelMapper.selectById(id);
    }

    /*修改信息*/
    @Override
    public void updatearoundTravel(AroundTravel aroundTravel) {
        aroundTravelMapper.updateById(aroundTravel);
    }

    @Override
    public void deletearoundTravelById(Integer id) {
        aroundTravelMapper.deleteById(id);
    }

}
